<%@ page contentType="text/html;charset=utf-8"%>
<%@page import="com.leruan.aasimp.entity.Board"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ page import="com.leruan.aasimp.entity.Mainpost"%>
<%@ page import="com.leruan.aasimp.entity.Forumuser"%>
<%@ page import="com.leruan.aasimp.entity.Reply"%>
<%@ page import="com.leruan.aasimp.util.Validators"%>
<%@ page import="java.util.Map.Entry"%>
<%@ page import="java.util.*"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
	Mainpost mainpost = (Mainpost)request.getAttribute("mainpost");
	Forumuser forumuser = (Forumuser)request.getAttribute("forumuser");
	Forumuser user = (Forumuser)request.getSession().getAttribute("user");
	List<Board> boards = (List<Board>)request.getAttribute("boards");
	String boardId =mainpost.getBoardId();
	Board board = (Board)request.getAttribute("board");
	
 %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns="http://www.w3.org/1999/xhtml">
<HEAD>
<SCRIPT src="js/common.js" type=text/javascript></SCRIPT>
<SCRIPT src="js/topic.js" type=text/javascript></SCRIPT>
<script charset="utf-8" src="<%=request.getContextPath()%>/kindeditor/kindeditor-min.js"></script>
<script charset="utf-8" src="<%=request.getContextPath()%>/kindeditor/kindeditor-jxhlext.js"></script>
<SCRIPT type=text/javascript>
	function replyTopic(user){
		if(<%=user==null%>){
			if(confirm("请先登录！")){
				document.location.href="loginOnly";
			}
		}
		else{
			document.getElementById("show").style.display='block';
		}
	}
	function toRegister(){
    window.location.href="toRegister";
    }
	
	function newTopic(boardId){
		if(<%=user==null%>){
			if(confirm("请先登录！")){
				document.location.href="loginOnly";
			}
		}else{
			document.location.href="newPost?boardId="+boardId;
		}
	}
	function doEdit(postId,boardId){
	   document.location.href="showEditPost?postId="+postId+"&boardId="+boardId;
	}
	function doDelete(postId){
	    document.location.href="deletePost?postId="+postId;
	}
</SCRIPT>	
<TITLE></TITLE>
<LINK href="styles/green/ejforum.css" type=text/css rel=stylesheet>
</HEAD>
<BODY onkeydown="if(event.keyCode==27) return false;">
<s:actionerror cssStyle="color:red"/>
<DIV class=wrap>
<div id=foruminfo>
    <table>
        <tr>
            <td >
                 <div style="height:73px; width: 193px; background-image: url('images/forumlogo.jpg')"></div>
            </td>
            <td align="right" width="1000%">
                <DIV id=foruminfo>
                <%if(null==user){
                %>
                <form action="login" onSubmit="checkfield(this); return false;" method="get">
                用户名：<input type=text id="username" name="username" size=13 maxlength=30 tabindex=1/>
                密码：<input type=password id="password1" name="password1" size=8 tabindex=2 onkeypress="if((event.keyCode?event.keyCode:event.charCode)==13) $('loginform').submit();"/>
                <INPUT type=hidden id="password" name="password">&nbsp;
                <button type="submit" name=loginsubmit tabIndex=3 style="width:46px">登录</button>
                <button type="button" name="register" tabIndex=3 style="width:46px" onclick="toRegister()">注册</button></form>
                <%
                } else{
                %>
                欢迎您! <a href="userDetails?username=<%=user.getUsername() %>&userId=<%=user.getUserId() %>"><%=user.getUsername() %> <a href="logout.action">退出登录</a>
                <%
                }%>
                </DIV>
            </td>
        </tr>
    </table>
</div>
<DIV class="mainbox viewtopic">
<H1>
 &raquo;&nbsp;<a href="index">首页</a>&raquo;&nbsp;<a href="boardPostList?boardId=<%=board.getBoardId()%>"><%=board.getBoardName() %></a> &raquo;&nbsp;<a href="viewPost?postId=<%=mainpost.getPostId() %>"><%=mainpost.getPostTitle() %></a>
<SELECT onchange="if(this.options[this.selectedIndex].value != ''){window.location = 'boardPostList?boardId='+this.options[this.selectedIndex].value;}" >
		<OPTION value="" selected>版块跳转 ...</OPTION> 
<%
	for(Board b:boards){
	%>
		<option value="<%=b.getBoardId() %>"><%=b.getBoardName() %></option>
	<%
	}
 %>
</SELECT>
</H1>
            <div class="pageNo" id="pageNo">
                <a href="viewPostQuery?no=1&postId=<%=mainpost.getPostId() %>">首页</a>
                <c:if test="${sessionScope.pageNoSale != 1}">
                    <a href="viewPostQuery?no=${sessionScope.pageNoSale-1}&postId=<%=mainpost.getPostId() %>">上一页</a>
                </c:if>
                <c:forEach var="i" begin="${sessionScope.pageNoCenterSale -2 }"
                    end="${sessionScope.pageNoCenterSale + 2}">
                    <c:if test="${i <= sessionScope.totalNoSale }">
                        <c:choose>
                            <c:when test="${i == sessionScope.pageNoSale}">
                                <a href="javascript:void(0)">${i}</a>
                            </c:when>
                            <c:otherwise>
                                <a href="viewPostQuery?no=${i}&postId=<%=mainpost.getPostId() %>">${i}</a>
                            </c:otherwise>
                        </c:choose>
                    </c:if>
                </c:forEach>
                <c:if test="${sessionScope.pageNoSale +4 < sessionScope.totalNoSale}">
                    <a href="viewPostQuery?no=${sessionScope.pageNoSale+1}&postId=<%=mainpost.getPostId() %>">下一页</a>
                </c:if>
                <a href="viewPostQuery?no=${sessionScope.totalNoSale}&postId=<%=mainpost.getPostId() %>">末页</a>
                &nbsp;&nbsp;&nbsp;&nbsp;共有<label style="color: red;">${sessionScope.totalSale}</label>条回复
            </div>
<TABLE cellSpacing=0 cellPadding=0>
  <TR>
    <TD class=postauthor rowspan="2">
      <%=forumuser.getUsername() %>
		<IMG alt="Rank: " src="images/star_5.gif" align="absmiddle" border="0"><IMG alt="Rank: " src="images/star_1.gif" align="absmiddle" border="0">
	  <DL class="profile">
	  	<DT>帖子&nbsp;</DT><DD>&nbsp;</DD>
	  	<DT>积分&nbsp;</DT><DD><%=forumuser.getScore() %>&nbsp;</DD>
	  </DL>				      
	  <UL>
	  	<LI class=friend><A href="./member/my_addfriend.jsp?uid=" target=_blank>加为好友</A></LI>
        <LI class=sms><A href="./member/sms_compose.jsp?uid=" target=_blank>发短消息</A></LI>
	  </UL>
	  </TD>
    <TD class=postdetail>
      <DIV class=postinfo> 
	  发表于&nbsp;<%=mainpost.getPostDate() %>
	  </DIV>
      <DIV class="postcontent">
      <DIV id="content_" class=contentmsg>
      	<%=mainpost.getContent() %>
      </DIV>
  </DIV>
  </TD>
  </TR>
  <TR>
    <TD class=postfooter>
      <DIV class=postactions><P>
      <% 
      if(forumuser.getUserId().equals(null==user?" ":user.getUserId())){
      %>
	     <a href="javascript:doEdit('<%=mainpost.getPostId() %>','<%=mainpost.getBoardId() %>');">修改</a>&nbsp;&nbsp;
 	     <a href="javascript:doDelete('<%=mainpost.getPostId() %>');">删除</a>&nbsp;&nbsp;
      <%
      } %>
	     <SPAN title="顶部" class="scrolltop" onclick="scroll(0,0)">TOP</SPAN> </P>
	     </DIV>
	     </TD>
	     </TR>
	     <%
	     int i = 0;
	     List<Reply> replyList = (List<Reply>)request.getAttribute("replyList");
		Map<String, Forumuser> forumuserList = (Map<String, Forumuser>)request.getAttribute("forumuserList");
	     Forumuser forumuserReply = new Forumuser(); 
	     for(Reply r : replyList){
	     i++;
	    	forumuserReply = forumuserList.get(r.getUserId());
	    	%>
	    	<tr>
	    	<TD class=postauthor rowspan="1">
		      <%=forumuserReply.getUsername() %>
				<IMG alt="Rank: " src="images/star_5.gif" align="absmiddle" border="0"><IMG alt="Rank: " src="images/star_1.gif" align="absmiddle" border="0">
			  <DL class="profile">
			  	<DT>帖子&nbsp;</DT><DD>&nbsp;</DD>
			  	<DT>积分&nbsp;</DT><DD><%=forumuserReply.getScore() %>&nbsp;</DD>
			  </DL>				      
			  <UL>
			  	<LI class=friend><A href="./member/my_addfriend.jsp?uid=" target=_blank>加为好友</A></LI>
		        <LI class=sms><A href="./member/sms_compose.jsp?uid=" target=_blank>发短消息</A></LI>
			  </UL>
			  </TD>
		    <TD class=postdetail>
		      <DIV class=postinfo><STRONG title="ID:"><SUP>#${(sessionScope.pageNoSale-1)*10}+<%=i %></SUP></STRONG> 
			  评论时间：&nbsp;<%=r.getReplyDate() %>
			  </DIV>
		      <DIV class="postcontent">
		      <DIV id="content_" class=contentmsg>
		      	<%=r.getReplyContent() %>
		      </DIV>
			  </DIV>
			  </TD>
	    	</tr>
	    	<%
	    	}
	      %>
	     </TABLE>
</DIV>

<DIV class=pages_btns>
<div class="pages"><a href="boardPostList?boardId=<%=boardId%>" class="next"> &lsaquo;&lsaquo; 返回主题列表</a></div>
<SPAN class=postbtn id="newtopictmp" onmouseover="$('newtopic').id = 'newtopictmp';this.id = 'newtopic';showMenu(this.id);">
<A href="javascript:newTopic('<%=boardId %>');"><IMG src="styles/green/images/newtopic.gif" border=0></A></SPAN>
<SPAN class=replybtn><A href="javascript:replyTopic('<%=user%>');">
<IMG alt="发表回复" src="styles/green/images/reply.gif" border=0></A></SPAN>
</DIV>

<DIV class="mainbox viewtopic" id="show" style="display: none;">
<form id="replyForm" action="reply" method="get">
<H1>帖子回复</H1>
<input type="hidden" id="postId" name="postId" value="<%=mainpost.getPostId() %>">
<input type="hidden" id="boardId" name="boardId" value="<%=mainpost.getBoardId() %>">
<input type="hidden" id="userId" name="userId" value="<%=null==user?"":user.getUserId() %>">
<TABLE  cellSpacing=0 cellPadding=0>
  <TR>
    <TD class=postauthor  rowspan="3">
      <%=null==user?"":user.getUsername() %>
		<IMG alt="Rank: " src="images/star_5.gif" align="absmiddle" border="0"><IMG alt="Rank: " src="images/star_1.gif" align="absmiddle" border="0">
	  <DL class="profile">
	  	<DT>帖子&nbsp;<br></DT><DD>&nbsp;<br></DD>
	  	<DT>积分&nbsp;<br></DT><DD><%=null==user?"":user.getScore() %>&nbsp;<br></DD>
	  </DL>				      
	  <UL>
	  	<LI class=friend><A href="./member/my_addfriend.jsp?uid=" target=_blank>加为好友</A><br></LI>
        <LI class=sms><A href="./member/sms_compose.jsp?uid=" target=_blank>发短消息</A><br></LI>
	  </UL>
	  </TD>
          <td height="300" align="left" bgcolor="#FFFFFF" style="padding-right:5px;" colspan="2"class=postdetail>
	  <DIV class=postinfo><STRONG title="ID:"><SUP>#</SUP></STRONG> 
	  replyTo:&nbsp; <%=forumuser.getUsername() %>
	  </DIV>
            <table height="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td width="100%" height="100%">
                  <textarea id="news_Id" name="replyContent" style="width:700px;height:300px;display:none;">
                  </textarea>
                </td>
              </tr>
            </table>
          </td>
  	</TR>
  		<TR>
  		    <TD class=postfooter>
      		<DIV class=postactions><P>
		     <input type="submit" value="提交" align="right" >
      		</P>
      		</DIV>
      		</TD>
  		</TR>
	     </TABLE>
</form>
</DIV>
<script language="javascript" type="text/javascript">
KE.show({
  id : 'news_Id',
  imageUploadJson : "<%=request.getContextPath()%>/support/information/topicNewsUpload.htm",
  flashUploadJson : "<%=request.getContextPath()%>/support/information/topicNewsUpload.htm?fileType=1",
  mediaUploadJson : "<%=request.getContextPath()%>/support/information/topicNewsUpload.htm?fileType=2"
});
</script> 
</BODY></HTML>
